@extends('admin.layouts.app')

@section('title', '用户详情')

@section('content')
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3>用户详情</h3>
    <div>
        @can('edit-users')
        <a href="{{ route('admin.users.edit', $user) }}" class="btn btn-warning">
            <i class="fas fa-edit me-2"></i>编辑
        </a>
        @endcan
        <a href="{{ route('admin.users.index') }}" class="btn btn-secondary">
            <i class="fas fa-arrow-left me-2"></i>返回列表
        </a>
    </div>
</div>

<div class="card">
    <div class="card-body">
        <div class="row">
            <div class="col-md-6">
                <h5>基本信息</h5>
                <table class="table table-borderless">
                    <tr>
                        <td width="30%"><strong>ID:</strong></td>
                        <td>{{ $user->id }}</td>
                    </tr>
                    <tr>
                        <td><strong>姓名:</strong></td>
                        <td>{{ $user->name }}</td>
                    </tr>
                    <tr>
                        <td><strong>邮箱:</strong></td>
                        <td>{{ $user->email }}</td>
                    </tr>
                    <tr>
                        <td><strong>邮箱验证:</strong></td>
                        <td>
                            @if($user->email_verified_at)
                                <span class="badge bg-success">已验证</span>
                                <small class="text-muted d-block">{{ $user->email_verified_at->format('Y-m-d H:i:s') }}</small>
                            @else
                                <span class="badge bg-warning">未验证</span>
                            @endif
                        </td>
                    </tr>
                    <tr>
                        <td><strong>创建时间:</strong></td>
                        <td>{{ $user->created_at->format('Y-m-d H:i:s') }}</td>
                    </tr>
                    <tr>
                        <td><strong>更新时间:</strong></td>
                        <td>{{ $user->updated_at->format('Y-m-d H:i:s') }}</td>
                    </tr>
                </table>
            </div>
            
            <div class="col-md-6">
                <h5>角色信息</h5>
                @if($user->roles->count() > 0)
                    <div class="mb-3">
                        @foreach($user->roles as $role)
                            <span class="badge bg-primary me-2">{{ $role->name }}</span>
                        @endforeach
                    </div>
                @else
                    <p class="text-muted">暂无角色</p>
                @endif
                
                <h5 class="mt-4">组织信息</h5>
                @if($user->organizations->count() > 0)
                    <div class="mb-3">
                        <h6>管理的组织</h6>
                        @if($user->managedOrganizations->count() > 0)
                            <ul class="list-group mb-3">
                                @foreach($user->managedOrganizations as $org)
                                    <li class="list-group-item d-flex justify-content-between align-items-center">
                                        <div>
                                            <strong>{{ $org->name }}</strong>
                                            <small class="d-block text-muted">{{ $org->code }}</small>
                                        </div>
                                        <a href="{{ route('admin.organizations.show', $org) }}" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </li>
                                @endforeach
                            </ul>
                        @else
                            <p class="text-muted">暂无管理的组织</p>
                        @endif
                        
                        <h6>所属组织</h6>
                        @if($user->organizations->where('pivot.is_admin', false)->count() > 0)
                            <ul class="list-group">
                                @foreach($user->organizations->where('pivot.is_admin', false) as $org)
                                    <li class="list-group-item d-flex justify-content-between align-items-center">
                                        <div>
                                            <strong>{{ $org->name }}</strong>
                                            <small class="d-block text-muted">{{ $org->code }}</small>
                                        </div>
                                        <a href="{{ route('admin.organizations.show', $org) }}" class="btn btn-sm btn-outline-primary">
                                            <i class="fas fa-eye"></i>
                                        </a>
                                    </li>
                                @endforeach
                            </ul>
                        @else
                            <p class="text-muted">暂无所属组织</p>
                        @endif
                    </div>
                @else
                    <p class="text-muted">暂无组织信息</p>
                @endif
                
                <h5 class="mt-4">权限信息</h5>
                @if($user->getAllPermissions()->count() > 0)
                    <div class="row">
                        @foreach($user->getAllPermissions() as $permission)
                            <div class="col-md-6 mb-2">
                                <span class="badge bg-secondary">{{ $permission->name }}</span>
                            </div>
                        @endforeach
                    </div>
                @else
                    <p class="text-muted">暂无权限</p>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection